package com.netbetter.langzheng.plugin.fileManager;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Controller;
import com.extjs.gxt.ui.client.mvc.View;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.netbetter.langzheng.commons.constants.AppEvents;
import com.netbetter.langzheng.plugin.fileManager.dto.ViewListEventDTO;
import com.netbetter.langzheng.plugin.fileManager.model.FileModel;
import com.netbetter.langzheng.plugin.fileManager.widget.ListViewPanel;

/**
 * 文件管理整个视图
 * 
 * @author 嘉陵江里捉鱼
 */
public class ListView extends View {

    private LayoutContainer container;
    private ListViewPanel   listviewPanel;

    public ListView(Controller controller) {
        super(controller);
    }

    protected void handleEvent(AppEvent event) {
        if (event.type == AppEvents.NAVLASTVIEW) {
            LayoutContainer wrapper = (LayoutContainer) Registry.get("center");
            wrapper.removeAll();
            wrapper.add(container);
            wrapper.layout();
        }

        if (event.type == AppEvents.ViewLIST) {
            ViewListEventDTO viewListEventDTO = (ViewListEventDTO) event.data;
            initListData(viewListEventDTO.getFileModel());
        }
        if (event.type == AppEvents.NavProperty) {
            FileModel file = (FileModel) event.data;
            initListData(file);
        }
    }

    /**
     * 初始化listView与相关事件
     * 
     * @param fileModel
     */
    protected void initListData(FileModel fileModel) {

    }

    @Override
    protected void initialize() {
        container = new LayoutContainer();

        BorderLayout layout = new BorderLayout();
        layout.setEnableState(false);
        container.setLayout(new FitLayout());

        listviewPanel = new ListViewPanel();
        listviewPanel.setLayout(new FitLayout());

        container.add(listviewPanel);
    }

}
